/* ========================================================================== */
/*   Log.cpp                           			                              */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/*   Logs the Gametime, Health and WeaponID when the player gets hit. Resets  */
/*		and gets entire log when requested.								      */
/* ========================================================================== */
#include "Log.h"

void Log::main()
{	
	for(;;)
	{
		RTOS::event e = wait( );
		std::cout << "Log::main() 1/2\n";
		if(ClearLogFlag == e)
		{
			std::cout << "Log::main() 1 1/2\n";
			for(unsigned int i = 0; i < 50; i++)
			{	
				log[i].player = 0;
				log[i].weapon = 0;
				log[i].health = 0;
				log[i].time = 0;
			}
			logCount = 0;
			std::cout << "Log::main() 1 2/2\n";
		}
		else if(GetLogFlag == e)
		{
			std::cout << "Log::main() 2 1/2\n";
			theReadLogHandler->WriteLog(log);
			std::cout << "Log::main() 2 2/2\n";
		}
		else if(LogChannel == e)
		{
			std::cout << "Log::main() 3 1/2\n";
			LogLine le = LogChannel.read();
			log[(short)logCount] = le;
			logCount++;
			std::cout << "Log::main() 3 2/2\n";
		}
		std::cout << "Log::main() 2/2\n";
	}
}

void Log::ClearLog()
{
	std::cout << "Log::ClearLog()1/2\n";
	ClearLogFlag.set();
	std::cout << "Log::ClearLog()2/2\n";
}

void Log::GetLog()
{
	std::cout << "Log::GetLog()1/2\n";
	GetLogFlag.set();
	std::cout << "Log::GetLog()2/2\n";
}

void Log::WriteLog(char p, char w, char h, short t)
{
	std::cout << "Log::WriteLog()1/2\n";
	LogChannel.write(LogLine(p, w, h, t));
	std::cout << "Log::WriteLog()2/2\n";
}
